/**
 * 将后台返回的菜单反序列化为路由对象
 * @param routes
 * @param menus
 */
function deserialization (routes, menus) {
	menus.forEach(menu => {
		let route = Object.assign({}, menu);

		if (menu.path) {
			if (menu.component) {
				route.component = () => import(`../views/${menu.component}.vue`);
				routes.push(route);
			}
		} else {
			if (menu.children) {
				deserialization(routes, menu.children);
			}
		}
	});
}

/**
 * 导出调用方法
 * @param routes
 * @param menus
 */
export default (routes, menus) => {
	deserialization(routes, menus);
}
